<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<jsp:useBean id="player" class="pe.lucene.web.myrating.Player" scope="session"/>    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@page import="org.hibernate.Session"%>

<%@page import="pe.lucene.web.myrating.HibernateUtil"%>
<%@page import="org.hibernate.Transaction"%>
<%@page import="pe.lucene.web.myrating.Rating" %>
<%@page import="java.util.Date"%><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<link rel="stylesheet" type="text/css" href="index.css" />
<title>Modify My Rating Complete</title>
</head>
<meta http-equiv="refresh" content="2;url=../index.jsp">
<body>

<%
    String num = request.getParameter("num");
    String date = request.getParameter("date");
    String ratingvalue = request.getParameter("ratingvalue");
    String vs_team = request.getParameter("vs_team");
    
    Session hbSession = null;
    Transaction tx = null;
    
    try {
        hbSession = HibernateUtil.currentSession();
        tx = hbSession.beginTransaction();
        
        Rating rating = (Rating) hbSession.get(Rating.class, new Integer(num));
        
        rating.setDate(new Date());
        rating.setRating(Integer.parseInt(ratingvalue));
        if (vs_team != null) {
        	int vs_team_int = 0;
        	
        	try {
        		vs_team_int = Integer.parseInt(vs_team);
        	} catch (NumberFormatException nfe) {
        		vs_team_int = -1;
        	} finally {
        	    rating.setTeam(vs_team_int);
        	}
        }
        
        hbSession.save(rating);
        out.println("Session updated<BR>");
        tx.commit();
        
    } catch(Exception ex) {
        out.println("Exception catch");
        out.println(ex.getMessage());
        ex.printStackTrace();
        if (tx != null) tx.rollback();
    } finally {
        HibernateUtil.closeSession();
        out.println("Finally close session");
    }

%>
</body>
</html>